#include "Subscript.h"
#include "IVisitor.h"

Subscript::Subscript(const exprTypePtr& value, const sliceTypePtr& slice, int ctx, int nodeId):
    exprType(nodeId),
    _value(value),
    _slice(slice),
    _ctx(ctx)
{
}
    
Subscript::~Subscript()
{
    
}
    
Ast::AstTypes Subscript::type() const
{
    return Ast::Subscript;
}
    

exprTypePtr Subscript::value()
{
    return _value;
}

void Subscript::setValue(const exprTypePtr& value)
{
    _value = value;
}

sliceTypePtr Subscript::slice()
{
    return _slice;
}

void Subscript::setSlice(const sliceTypePtr& slice)
{
    _slice = slice;
}

int Subscript::ctx()
{
    return _ctx;
}

void Subscript::setCtx(int ctx)
{
    _ctx = ctx;
}

    
QString Subscript::toString() const
{
    return QString("Subscript[value=%1, slice=%2, ctx=%3]").
                arg(_value ? _value->toString():"").
                arg(_slice ? _slice->toString():"").
                arg(_ctx);
}
    
void Subscript::accept(IVisitor* visitor, const SimpleNodePtr& node)
{
    visitor->visitSubscript(node.dynamicCast<Subscript>());
}
    
void Subscript::traverse(IVisitor* visitor)
{
    if (_value != NULL)
        _value->accept(visitor, _value);
    if (_slice != NULL)
        _slice->accept(visitor, _slice);
}